using System;
using RestSharp; //from http://restsharp.org/
using RestSharp.Authenticators;

namespace Flare
{
    public class Message
    {
        public Message(string name, string message, string elementId)
        {
            Name = name;
            TextMessage = message;
            ElementId = elementId;
        }

        public String Name { get; set; }
        public String TextMessage { get; set; }
        public String ElementId { get; set; }

        public string notifyBoxcar(string msg, int id)
        {
            string results = "";
            string boxcarUser = "{Username}"; //temporary until we save this to registry
            string boxcarPass = "{Password}"; //temporary until we save this to registry
            string source_url = "http://{name}.campfirenow.com/room/xxxxx";
            try
            {
                var client = new RestClient("https://boxcar.io/notifications/");
                client.Authenticator = new HttpBasicAuthenticator(boxcarUser, boxcarPass);
                var request = new RestRequest(Method.POST);
                request.AddHeader("Accept", "application/json");

                //add parameters for all properties on an object
                request.AddParameter("notification[from_screen_name]", "[Campfire]\n");
                request.AddParameter("notification[message]", Name + " wrote:\n" + TextMessage);
                request.AddParameter("notification[from_remote_servie_id]", ElementId); //id should be unique to avoid duplication
                request.AddParameter("notification[source_url]", source_url);
                request.AddParameter("notification[icon_url]", "http://www.37signals.com/svn/images/campfire-logo-for-fluid.png");
                request.AddParameter("notification[sound]", "Boing"); //the sound name must match a sound name in the Boxcar app

                //execute the request
                RestResponse response = client.Execute(request);
                var content = response.Content; //raw content as string
                results = content.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return results;
        }
    }
}